package com.ruibang.glass.material.service.impl.gj;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruibang.glass.material.domain.req.ycl.MaterialInventoryReq;
import com.ruibang.glass.material.entity.gj.MaterialGJInventoryManagement;
import com.ruibang.glass.material.mapper.gj.GMaterialGJInventoryManagementMapper;
import com.ruibang.glass.material.service.gj.GMaterialGJInventoryManagementService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 原材料库存管理表 服务实现类
 * </p>
 *
 * @author mameng
 * @since 2024-04-01
 */
@Service
public class GMaterialGJInventoryManagementServiceImpl extends ServiceImpl<GMaterialGJInventoryManagementMapper, MaterialGJInventoryManagement> implements GMaterialGJInventoryManagementService {

    @Override
    public IPage<MaterialGJInventoryManagement> getPage(MaterialInventoryReq materialInventoryReq) {
        LambdaQueryWrapper<MaterialGJInventoryManagement> queryWrapper = Wrappers.<MaterialGJInventoryManagement>lambdaQuery();
        if (StringUtils.isNotBlank(materialInventoryReq.getMaterialCode())) {
            queryWrapper.like(MaterialGJInventoryManagement::getMaterialCode, materialInventoryReq.getMaterialCode());
        }
        if (StringUtils.isNotBlank(materialInventoryReq.getMaterialName())) {
            queryWrapper.like(MaterialGJInventoryManagement::getMaterialName, materialInventoryReq.getMaterialName());
        }
        if (StringUtils.isNotBlank(materialInventoryReq.getStorageLocation())) {
            queryWrapper.like(MaterialGJInventoryManagement::getStorageLocation, materialInventoryReq.getStorageLocation());
        }
        if (StringUtils.isNotBlank(materialInventoryReq.getSupplier())) {
            queryWrapper.like(MaterialGJInventoryManagement::getSupplier, materialInventoryReq.getSupplier());
        }
        if (StringUtils.isNotBlank(materialInventoryReq.getBatchNumber())) {
            queryWrapper.like(MaterialGJInventoryManagement::getBatchNumber, materialInventoryReq.getBatchNumber());
        }
        if (StringUtils.isNotBlank(materialInventoryReq.getBarcodeNumber())) {
            queryWrapper.like(MaterialGJInventoryManagement::getBarcodeNumber, materialInventoryReq.getBarcodeNumber());
        }

        Page<MaterialGJInventoryManagement> materialWarehouseInfoPage = baseMapper.selectPage(new Page<>(materialInventoryReq.getPageNo(), materialInventoryReq.getPageSize()),
                queryWrapper.orderByDesc(MaterialGJInventoryManagement::getCreateTime)
        );
        return materialWarehouseInfoPage;

    }
}
